package com.qf.utils;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * zookeeper操作工具类
 * @author zhaojian
 */
public class ZkUtils {

    /**
     * 获取集群节点操作对象
     * @return
     */
    public static CuratorFramework getCf(){
        //重试策略
        //参数一：连接等待时间  参数二：重试次数
        RetryPolicy retryPolicy=new ExponentialBackoffRetry(3000,1);
        CuratorFramework cf = CuratorFrameworkFactory.builder().retryPolicy(retryPolicy).connectString("120.48.49.214:2182,120.48.49.214:2183,120.48.49.214:2184").build();
        //启动客户端
        cf.start();

        //4. 返回对象
        return cf;
    }
}